package com.example.venue_reservation_service.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.venue_reservation_service.domain.Device;
import com.example.venue_reservation_service.mapper.DeviceMapper;
import com.example.venue_reservation_service.service.DeviceService;
import jakarta.annotation.Resource;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
* @author 31586
* @description 针对表【venue_device】的数据库操作Service实现
* @createDate 2025-06-29 14:38:46
*/
@Service
public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> implements DeviceService {

    @Resource
    private DeviceMapper deviceMapper;

    // 模拟设备数据
    @Override
    public Device generateDeviceData() {
        Device device = new Device();
        device.setTimestamp(LocalDateTime.now());
        device.setTemperature(20 + Math.random() * 15);
        device.setHumidity(30 + Math.random() * 50);
        device.setFanStatus(device.getTemperature() > 25 ? 1 : 0);
        device.setWarningStatus((device.getTemperature() > 30 ||
                device.getHumidity() > 70 ||
                device.getHumidity() < 30) ? 1 : 0);
        return device;
    }

    // 获取最新设备数据
    @Override
    public List<Device> getLatestDevices() {
        return deviceMapper.selectLatestDevices(50);
    }

}




